﻿using BCCommon;
using BCDto.OA.BusinessTypeRecord;
using BCService.OA.BusinessTypeRecord;
using BlackCoffeeRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System;

namespace BlackCoffeeRESTful.Controllers.Management.OA.BusinessTypeRecord
{
    /// <summary>
    /// OA申请业务相关信息
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class BusinessTypeRecordController : ManagementBaseController
    {
        private readonly IBusinessTypeRecordService businessTypeRecordService;

        public BusinessTypeRecordController(IBusinessTypeRecordService businessTypeRecordService)
        {
            this.businessTypeRecordService = businessTypeRecordService;
        }

        /// <summary>
        /// 分页获取OA业务类型记录(列表)
        /// </summary>
        /// <param name="typeName"></param>
        /// <param name="start">创建时间开始</param>
        /// <param name="end">创建时间结束</param>
        /// <param name="ascending">是否升序排序</param>
        /// <param name="pageIndex">分页页码</param>
        /// <param name="pageSize">分页页数</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<BusinessTypeRecordDto>), 200)]
        public IActionResult Query([FromQuery(Name = "type_name")]string typeName,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "ascending")]bool? ascending,
            int pageIndex = 1,
            int pageSize = 10)
        {
            return this.Ok(businessTypeRecordService.GetList(typeName, start, end, ascending, pageIndex, pageSize));
        }

        /// <summary>
        /// 新增一条OA业务类型
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Log("新增一条OA业务类型")]
        [ProducesResponseType(typeof(BusinessTypeRecordDto), 200)]
        public IActionResult Post([FromBody]BusinessTypeRecordRequestDto requestDto)
        {
            var result = this.businessTypeRecordService.Create(requestDto);
            return Created(string.Format("api/v1/sim/BusinessTypeRecord/{0}", result.BusinessTypeRecordId), result);
        }

        /// <summary>
        /// 修改一条OA业务类型
        /// </summary>
        /// <returns></returns>
        [HttpPut("{business_type_record_id}")]
        [Log("修改一条OA业务类型")]
        [ProducesResponseType(typeof(BusinessTypeRecordDto), 200)]
        public IActionResult Put([FromRoute(Name = "business_type_record_id")]long businessTypeRecordId, [FromBody]BusinessTypeRecordRequestDto requestDto)
        {
            return this.Ok(this.businessTypeRecordService.Update(businessTypeRecordId, requestDto));
        }
    }
}